package edu.nanyang.dao;

import edu.nanyang.domain.OptionInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface OptionInfoDao {
    /**
     * 通过题号获取该题的四个选项
     * @param questionNumId
     * @return
     */

    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "questionNumId", column = "question_num_id"),
            @Result(property = "optionContent", column = "option_content"),
            @Result(property = "optionType", column = "option_type"),
            @Result(property = "createTime", column = "create_time")
    })
    @Select("SELECT * FROM option_info WHERE question_num_id=#{questionNumId} ORDER BY option_type ASC")
    List<OptionInfo> getByQuestionNumId(int questionNumId);

    /**
     * 通过题号和选项类型获取该选项
     * @param questionNumId
     * @param optionType
     * @return
     */
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "questionNumId", column = "question_num_id"),
            @Result(property = "optionContent", column = "option_content"),
            @Result(property = "optionType", column = "option_type"),
            @Result(property = "createTime", column = "create_time"),
    })
    @Select("SELECT * FROM option_info WHERE question_num_id=#{questionNumId} AND option_type=#{optionType}")
    OptionInfo getByNumIdAndType(int questionNumId, String optionType);

    @Update("update option_info set operate_time=now(),question_num_id=#{questionNumId},option_content=#{optionContent},option_type=#{optionType} where id=#{id}")
    int update(OptionInfo optionInfo);

    @Insert("insert into option_info(question_num_id,option_content,option_type,create_time) values(#{questionNumId},#{optionContent},#{optionType},now())")
    int add(OptionInfo optionInfo);
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "questionNumId", column = "question_num_id"),
            @Result(property = "optionContent", column = "option_content"),
            @Result(property = "optionType", column = "option_type"),
            @Result(property = "createTime", column = "create_time"),
    })
    @Select("select * from option_info where id=#{id}")
    OptionInfo getById(int id);
    @Delete("delete from option_info where id=#{id}")
    int deleteById(int id);
}
